<template>
  <el-menu
    default-active="2"
    background-color="#333744"
    text-color="#fff"
    active-text-color="#409eff"
    :router="isPath"
    :collapse="isCollapse"
    unique-opened
    :collapse-transition="false">
    <div class="menu-collapse"
         @click="changeCollapse">
         |||
    </div>
    <el-submenu
      v-for="(value1, index1) in menuList"
      :key="index1"
      :index="value1.id + ''">
      <template #title>
        <i :class="iconItems[value1.id]"></i>
        <span>{{ value1.authName }}</span>
      </template>
      <el-menu-item
        v-for="(value2, index2) in value1.children"
        :key="index2"
        :index="'/' + value2.path"
        @click="menuRouter('/' + value2.path)">
        <template #title>
          <i class="el-icon-menu"></i>
          <span>{{ value2.authName }}</span>
        </template>
      </el-menu-item>
    </el-submenu>
  </el-menu>
</template>

<script>
export default {
  name: 'HomeAside',
  data () {
    return {
      iconItems: {
        125: 'iconfont icon-user',
        103: 'iconfont icon-tijikongjian',
        101: 'iconfont icon-shangpin',
        102: 'iconfont icon-danju',
        145: 'iconfont icon-baobiao'
      },
      isCollapse: false
    }
  },
  props: {
    menuList: {
      type: Array,
      default () {
        return []
      }
    },
    // 是否激活点击菜单跳转路由
    isPath: {
      type: Boolean,
      default () {
        return false
      }
    }
  },
  methods: {
    // 1. 收缩菜单
    changeCollapse () {
      this.isCollapse = !this.isCollapse
      this.$emit('changeCollapse', this.isCollapse)
    },
    // 2. 点击菜单实现路由跳转
    menuRouter (path) {
      if (this.$route.path === path) return false
      this.$router.push(path)
    }
  }
}
</script>

<style scoped lang="less">
.el-menu {
  border: none;
  span {
    margin: 8px;
  }
  .menu-collapse {
    text-align: center;
    color: #fff;
    letter-spacing: 0.2em;
    font-size: 10px;
    background-color: #4a5064;
    padding: 5px;
    cursor: pointer;
  }
}
</style>
